//
//  EMMyMessageViewController.m
//  ElectronicMall
//
//  Created by 史伟文 on 14/12/25.
//  Copyright (c) 2014年 cczu. All rights reserved.
//

#import "EMMyMessageViewController.h"
#import "UINavigationController+EMNavi.h"
#import "UserInfo.h"
@interface EMMyMessageViewController ()
{
    NSArray *messageArray;
}

@end

@implementation EMMyMessageViewController
- (void)hideBottomBar
{
    for(UIView *view in self.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
            view.hidden = YES;
    }
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self hideBottomBar];
    [self.navigationController setNavigationMode:EMNavigationModeDefault andSubMode:0];
    self.navigationItem.title = @"我的消息";
    
    UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
    button.frame=CGRectMake(0, 0, 30, 32);
    [button setImage:[UIImage imageNamed:@"button_导航_返回_白"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem =[[UIBarButtonItem alloc]initWithCustomView:button];
}
- (void)backAction: (UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    NSDictionary *dic = [[UserInfo sharedUserInfo] valueForKey:@"userInfo"];
    messageArray = @[@{@"title":@"新鲜红富士上市啦",@"content":@"最新畅销最新畅销，最新畅销最新畅销，最新畅销最新畅销最新畅销",@"date":@"12-12",},@{@"title":@"新鲜红富士上市啦",@"content":@"最新畅销最新畅销，最新畅销最新畅销，最新畅销最新畅销最新畅销",@"date":@"12-12",}, @{@"title":@"新鲜红富士上市啦",@"content":@"最新畅销最新畅销，最新畅销最新畅销，最新畅销最新畅销最新畅销",@"date":@"12-14",}, @{@"title":@"新鲜红富士上市啦",@"content":@"最新畅销最新畅销，最新畅销最新畅销，最新畅销最新畅销最新畅销",@"date":@"12-12",}];
    
    UITableView *messageTable = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    messageTable.delegate = self;
    messageTable.dataSource = self;
    [self.view addSubview:messageTable];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return messageArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"messCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:0 reuseIdentifier:cellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    NSDictionary *aMessage = messageArray[indexPath.row];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 250, 20)];
    titleLabel.text = [NSString stringWithFormat:@"%@",aMessage[@"title"]];
    titleLabel.textColor = [UIColor grayColor];
    titleLabel.font = [UIFont fontWithName:HEITIMEDIUM size:16];
    [cell addSubview:titleLabel];
    UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(260, 10, 50, 20)];
    dateLabel.text = aMessage[@"date"];
    dateLabel.textColor = [UIColor grayColor];
    dateLabel.font = [UIFont fontWithName:HEITILIGHT size:14];
    [cell addSubview:dateLabel];
    UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 30, 280, 40)];
    contentLabel.numberOfLines = 2;
    contentLabel.text = aMessage[@"content"];
    contentLabel.textColor = [UIColor grayColor];
    contentLabel.font = [UIFont fontWithName:HEITILIGHT size:14];
    [cell addSubview:contentLabel];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}
@end
